package com.health.ts.controller.sysmanage;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.health.ts.constant.ApiResult;
import com.health.ts.entity.sysmanage.SysMenuAuthority;
import com.health.ts.service.sysmanage.SysMenuAuthorityService;
/**
 * 权限菜单管理
 * @author Administrator
 */
@Controller
@RequestMapping(value = "/api/authMenu")
public class AuthorityMenuController {
	
	@Autowired
	SysMenuAuthorityService  sysMenuAuthorityService;
	
	/**
	 * 权限菜单关联
	 * @param sma
	 * @return
	 */
	@RequestMapping(value="/addAuthMenu", method=RequestMethod.POST)
	public ApiResult addAuthMenu(@RequestBody SysMenuAuthority sma) {
		sysMenuAuthorityService.saveOrUpdate(sma);
		return ApiResult.success();
	}
	
	/**
	 * 删除权限菜单关联
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
	public ApiResult deleteAuthMenu(@PathVariable String id) {
		sysMenuAuthorityService.removeById(id);
		return ApiResult.success();
    }
	
	/**
	 * 根据权限查询菜单
	 * @return
	 */
	@RequestMapping(value = "/listAuthMenu",method=RequestMethod.POST)
	public ApiResult listAuthMenu(@PathVariable String id) {
		QueryWrapper<SysMenuAuthority> wrapper = new QueryWrapper<SysMenuAuthority>();
		if (StringUtils.isNotEmpty(id)) {
			wrapper.eq("authority_id", id);
		}
		List<SysMenuAuthority> list = sysMenuAuthorityService.list(wrapper);
		return ApiResult.success(list);
	}
}
